package com.bifrost.util;

import com.bifrost.entity.MerchantStore;
import com.bifrost.entity.User;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ArrayUtils;

import java.util.List;
import java.util.Set;

/**
 * 查询参数相关方法
 */
public class QueryUtils {

    /**
     * 根据传入的merchantIds与当前用户的门店权限，返回门店查询条件id集合
     * @return
     */
    public static List<Long> getMerchantIds(User currentUser, Long[] merchantStoreIds){
        List<Long> merchantStoreIdList = Lists.newArrayList();
        if(ArrayUtils.isEmpty(merchantStoreIds)){//当未传入门店id时，查询条件为当前用户默认的门店权限
            Set<MerchantStore> merchantStores = currentUser.getMerchantStores();
            //Set<MerchantStore> merchantStores = null;
            if(CollectionUtils.isNotEmpty(merchantStores)){
                for(MerchantStore merchantStore : merchantStores){
                    merchantStoreIdList.add(merchantStore.getMerchantId());
                }
            }
        }else{
            for(int i = 0;i < merchantStoreIds.length; i ++){
                merchantStoreIdList.add(merchantStoreIds[i]);
            }
        }
        return merchantStoreIdList;
    }

}
